package com.zboot.zbootadmin.project.system.log.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.zboot.zbootadmin.project.system.log.entity.SysLog;
import com.zboot.zbootadmin.project.system.log.entity.dto.LogDto;
import com.zboot.zbootadmin.project.system.log.mapper.SysLogMapper;
import com.zboot.zbootadmin.project.system.log.service.SysLogService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 日志表 服务实现类
 * </p>
 *
 * @author zyt
 * @since 2020-10-12
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Override
    public JSONObject getLogList(LogDto logDto) {

        QueryWrapper queryWrapper = new QueryWrapper();
        if (logDto!=null) {
            if (!"".equals(logDto.getBeginTime()) && logDto.getBeginTime()!=null && !"".equals(logDto.getEndTime()) && logDto.getEndTime()!=null) {
                queryWrapper.between("create_time",logDto.getBeginTime(),logDto.getEndTime());
            }
        }
        queryWrapper.orderByDesc("create_time");
        if (logDto.getPageNum()!=0 && logDto.getPageSize()!=0) {
            PageHelper.startPage(logDto.getPageNum(),logDto.getPageSize());
        }

        JSONObject result = new JSONObject();
        result.put("result",this.list(queryWrapper));
        result.put("total",this.count(queryWrapper));
        return result;
    }
}
